#!/bin/bash
#leao:Thu Aug 22 02:48:52 PM CST 2024
#!/bin/bash  
  
sumLines=0  
sumCode() {  
    local path=$1  
    for val in $(ls -a "$path"); do   
      if [ "$val" != '.' ] && [ "$val" != '..' ];then     
            
            if [ -d "$path/$val" ]; then  
                sumCode "$path/$val" 
                
            else  
                case $val in  
                    *.c) 
                    echo "$val" 
                        lines=$(cat "$path/$val" | wc -l) 
                        ((sumLines += lines))             
                        ;;  
                esac  
            fi  
        fi  
    done  
}  
  
path1=$1  
if [ -z "$path1" ]; then  
    echo "error: argc is NULL"  
    exit 1  
fi  
if [ ! -d "$path1" ]; then  
    echo "参数不是有效路径"  
    exit 1  
fi  
sumCode "$path1"  
printf "该路径下一共有%d行c语言代码\n" "$sumLines"  